home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / zindent7.zip / ZINSTR.INC < prev    next >
Text File  |  1987-03-30  |  14KB  |  610 lines

  1.  
  2. (********************************************************************)
  3. (*                                                                  *)
  4. (*  Include File  STRING.INC                                        *)
  5. (*  Library of common string  PROCEDURES                            *)
  6. (*  v. 0800am, sun, 28.Mar.87, Glen Ellis                           *)
  7. (*                                                                  *)
  8. (********************************************************************)
  9.  
  10. (*---
  11.  
  12. Major routines summary :
  13.  
  14. pAllCaps (line) upper case full line
  15. pUpCaseFirst (line) upper case first word
  16.  
  17. pTrim* (line) simple trim spaces
  18. pTrim*Cnt (line,x) trim with counter
  19.  
  20. pPad* (line,len) simple pad spaces
  21. pPad*Cnt (line,cnt) pad with counter
  22.  
  23. pExpand* (line,chx,max) complex pad
  24. pShrink* (line,chx,max) complex trim
  25. pJust* (line,len)
  26.  
  27. pIndent complex required by KEYWORD
  28. pLineCount prefixes linecount str
  29.  
  30. pSayLnCJ (line,linelen);
  31. pSayLnLJ (line,linelen);
  32. pSayLnRJ (line,linelen);
  33.  
  34. pSayReadCJ (line,linelen,readlen);
  35. pSayReadLM (line,linelen,readlen);
  36.  
  37. pIndent() left margin restoration used by KeyWord procedures.
  38. pINDENT( var iLine : THEstr; iPos : integer; iMax : integer);
  39.  
  40. ---*)
  41.  
  42.  
  43. (********************************************************************)
  44.  
  45. procedure    pALLCAPS( var LINE : thestr );
  46.  
  47. var i : integer;
  48.  
  49. begin
  50.    FOR i := 1 to length(line)
  51.       do  Line[i] := upcase(Line[i]);
  52. end;
  53.  
  54.  
  55. (********************************************************************)
  56.  
  57. procedure    pUpCaseFirst( var LINE : thestr );
  58.  
  59. var i, max : integer;
  60.  
  61. begin
  62.    IF pos(' ',line) > 1 then max := pos(' ',line)
  63.    ELSE max := length(line);
  64.    FOR i := 1 to max
  65.       do  Line[i] := upcase(Line[i]);
  66. end;
  67.  
  68. (********************************************************************)
  69.  
  70. procedure pTrimL( var line : thestr);
  71.  
  72. (* line length is shortened *)
  73.  
  74. var
  75. byte : string1;
  76. len  : integer;
  77.  
  78. begin (* proc *)
  79.    IF length(line) > 1
  80.    then
  81.    begin
  82.       (* fetch byte on extreme left end *)
  83.       byte := Line[1];
  84.       (* trim left end <space> character, if len > 1 *)
  85.       while byte = ' ' do
  86.       begin
  87.          IF length(line) > 0
  88.          then
  89.          begin
  90.             delete(Line,1,1);
  91.             byte := Line[1];      (* next delete char *)
  92.          end
  93.          ELSE   (* force while loop to exit *)
  94.          byte := '.';
  95.       end; (* while *)
  96.    end; (* if *)
  97. end; (* proc *)
  98.  
  99.  
  100. (********************************************************************)
  101.  
  102. procedure pTrimR(var line : THEstr );
  103.  
  104. (* line length is shortened *)
  105.  
  106. var
  107. byte : string1;
  108. len  : integer;
  109.  
  110. begin (* proc *)
  111.    IF length(line) > 1
  112.    then
  113.    begin
  114.       (* fetch byte on extreme right end *)
  115.       len := length(Line);
  116.       byte := LINE[Len];
  117.       (* trim right end <space> character *)
  118.       WHILE (Byte = ' ') do
  119.       begin
  120.          IF length(line) > 0
  121.          then
  122.          begin
  123.             delete(Line,Len,1);
  124.             Len := length(Line);
  125.             Byte := Line[Len];
  126.          end
  127.          ELSE   (* force while loop to exit *)
  128.          byte := '.';
  129.       end; (* while *)
  130.    end; (* if *)
  131. end; (* proc *)
  132.  
  133.  
  134. (********************************************************************)
  135.  
  136. procedure pTrimLR( var LRLine : thestr );
  137.  
  138. (* trim left / trim right *)
  139. (* line length is shortened *)
  140.  
  141. var
  142. byte : string1;
  143. len  : integer;
  144.  
  145. begin (* proc *)
  146.    IF length(LRline) > 1 then
  147.    begin
  148.       pTrimR( LRLine );
  149.       pTrimL( LRLine );
  150.    end; (* if *)
  151. end; (* proc *)
  152.  
  153.  
  154. (********************************************************************)
  155.  
  156. procedure pTrimLCnt( var Line : thestr ; var Cnt : nbr );
  157.  
  158. (* trim left and count spaces *)
  159. (* line length is shortened *)
  160. (* Count is useful for restoring, or re-margining a text line. *)
  161.  
  162. var
  163. byte : string1;
  164. len  : integer;
  165.  
  166. begin (* proc *)
  167.    IF length(line) > 1
  168.    then
  169.    begin
  170.       (* fetch byte on extreme left end *)
  171.       byte := Line[1];
  172.       Cnt := 0;
  173.       (* trim left end <space> character, if len > 1 *)
  174.       WHILE byte = ' '
  175.       do
  176.       begin
  177.          IF length(line) > 0
  178.          then
  179.          begin
  180.             delete(Line,1,1);
  181.             byte := Line[1];      (* next delete char *)
  182.             Cnt := Cnt+1;
  183.          end
  184.          ELSE   (* force while loop to exit *)
  185.          byte := '.';
  186.       end; (* while *)
  187.    end; (* if *)
  188. end; (* proc *)
  189.  
  190.  
  191. (********************************************************************)
  192.  
  193. procedure pTrimRCnt(var Line : THEstr; var Cnt : nbr );
  194.  
  195. (* trim right and count spaces *)
  196. (* line length is shortened *)
  197. (* Count is usefile for restoring, or re-margining a text line. *)
  198.  
  199. var
  200. byte : string1;
  201. len  : integer;
  202.  
  203. begin (* proc *)
  204.    IF length(line) > 1
  205.    then
  206.    begin
  207.       (* fetch byte on extreme right end *)
  208.       len := length(Line);
  209.       byte := line[Len];
  210.       Cnt := 0;
  211.       (* trim right end <space> character *)
  212.       WHILE (Byte = ' ')
  213.       do
  214.       begin
  215.          IF length(line) > 0
  216.          then
  217.          begin
  218.             delete(Line,Len,1);
  219.             Len := length(Line);
  220.             Byte := Line[Len];
  221.             Cnt := Cnt+1;
  222.          end
  223.          ELSE   (* force while loop to exit *)
  224.          byte := '.';
  225.       end; (* while *)
  226.    end; (* if *)
  227. end; (* proc *)
  228.  
  229.  
  230.  
  231. (********************************************************************)
  232.  
  233. procedure pTrimLCntR( var LCRline : thestr ; var Cnt : nbr );
  234.  
  235. (* trim left and count spaces / trim right and without counting spaces *)
  236. (* line length is shortened *)
  237. (* called by KeyWord procedures *)
  238.  
  239. var
  240. byte : string1;
  241. len  : integer;
  242.  
  243. begin (* proc *)
  244.    IF length(LCRline) > 1
  245.    then
  246.    begin
  247.       pTrimR( LCRline );
  248.       pTrimLCnt( LCRline, Cnt );
  249.    end;
  250. end; (* proc *)
  251.  
  252.  
  253.  
  254. (********************************************************************)
  255.  
  256. procedure pPADL(var LINE : THEstr ; LEN : integer);
  257.  
  258. (* LINE  = incoming string to be altered
  259. (* LEN   = left margin length
  260. *)
  261.  
  262. var
  263. y : integer;
  264. mark : string1;
  265.  
  266. begin (* proc *)
  267.    mark   := ' ';
  268.    FOR y := 1 to len
  269.       do line := mark + line;
  270. end; (* proc *)
  271.  
  272.  
  273. (********************************************************************)
  274.  
  275. procedure pPADR(var LINE : THEstr ; LEN : integer);
  276.  
  277. (* LINE  := incoming string to be altered
  278. (* LEN   := right margin length
  279. *)
  280.  
  281. var
  282. y : integer;
  283. mark : string1;
  284.  
  285. begin (* proc *)
  286.    mark   := ' ';
  287.    FOR y := 1 to len
  288.       do line := line + mark;
  289. end; (* proc *)
  290.  
  291.  
  292. (***************************************************************************)
  293.  
  294. procedure pEXPANDL(var LINE :THEstr; CHX :string1; MAX :integer);
  295.  
  296. (* LINE   = incoming string to be altered
  297. (* CHX   = character to use
  298. (* MAX   = max length of expanded line
  299. *)
  300.  
  301. var
  302. y : integer;
  303.  
  304. begin (* proc *)
  305.    WHILE length(line) < max
  306.       do line := chx + line;
  307. end; (* proc *)
  308.  
  309.  
  310. (***************************************************************************)
  311.  
  312. procedure pEXPANDR(var LINE :THEstr; CHX :string1; MAX :integer);
  313.  
  314. (* LINE   = incoming string to be altered
  315. (* CHX   = character to use
  316. (* MAX   = max length of expanded line
  317. *)
  318.  
  319. var
  320. y : integer;
  321.  
  322. begin (* proc *)
  323.    WHILE length(line) < max
  324.       do line := line + chx;
  325. end; (* proc *)
  326.  
  327.  
  328. (********************************************************************)
  329.  
  330. procedure pSHRINKL(var LINE :THEstr; CHX :string1; MIN :integer);
  331.  
  332. (* shrink the line, not less than minimum length
  333. (* LINE   = incoming string to be altered
  334. (* CHX   = character to use
  335. (* MIN   = min length of shrinked line
  336. *)
  337.  
  338. begin (* proc *)
  339.    pTRIML(LINE);
  340.    pEXPANDL(LINE,CHX,min);
  341. end; (* proc *)
  342.  
  343.  
  344. (********************************************************************)
  345.  
  346. procedure pSHRINKR(var LINE :THEstr; CHX :string1; MIN :integer);
  347.  
  348. (* purpose : shrink line, not less than minimum length
  349. (* LINE   = incoming string to be altered
  350. (* CHX   = character to use
  351. (* MIN   = min length of shrinked line
  352. *)
  353.  
  354. begin (* proc *)
  355.    pTRIMR(LINE);
  356.    pEXPANDR(LINE,CHX,min);
  357. end; (* proc *)
  358.  
  359.  
  360. (******